home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * $ FILE : lines.c
- * $ VERSION : 1
- * $ REVISION : 2
- * $ DATE : 08-Dec-93 18:31
- * $
- * $ Author : mvk
- * $
- *
- * This is a line drawing demo for the Amiga or EGS .
- * For running under EGS please compiler with
- * sc DEF=EGS lines.c LINK
- *
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <intuition/intuition.h>
- #include <graphics/text.h>
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
-
- USHORT wakeup; /* Wake me up for event */
- USHORT class; /* Intu event class */
- USHORT code; /* Intu event code */
-
- #ifndef EGS
-
- struct Window *w;
- struct RastPort *rp,*cdrp;
- struct ViewPort *vp;
- struct IntuiMessage *message;
-
- #define MIX_CLOSEWINDOW CLOSEWINDOW
- #define MIX_NEWSIZE NEWSIZE
-
-
-
- #else
-
- /*
- ** EGS Include & Variablen Stuff
- **
- **
- */
-
- #include <egs/egsintui.h>
- #include <egs/egsgfx.h>
-
- #include <egs/proto/egsintui.h>
- #include <egs/proto/egsgfx.h>
-
- struct EG_RastPort *rp,*cdrp;
- struct EI_Window *w;
- struct EI_EIntuiMsg *message;
-
- struct Library *EGSGfxBase;
- struct Library *EGSIntuiBase;
-
-
- #define MIX_CLOSEWINDOW EI_iCLOSEWINDOW
- #define MIX_NEWSIZE EI_iNEWSIZE
-
- /*
- */
-
-
- #endif
-
- /* Proto */
-
- int event(void);
- void crash(char *string);
- void exit(int i);
-
-
-
-
- /************************ Window Defines ***********************************/
- #ifndef EGS
-
- struct NewWindow nw = {
- 100,100, /* Starting corner */
- 300,100, /* Width, height */
- 2,1, /* detail, block pens */
- MIX_CLOSEWINDOW | MIX_NEWSIZE, /* IDCMP flags */
- WINDOWDEPTH | WINDOWDRAG | WINDOWCLOSE | GIMMEZEROZERO | WINDOWSIZING,
- /* Window flags */
- NULL, /* Pointer to first gadget */
- NULL, /* Pointer to checkmark */
- "Nervous Lines", /* title */
- NULL, /* screen pointer */
- NULL, /* bitmap pointer */
- 50,50,640,400, /* window not sized */
- WBENCHSCREEN /* type of screen */
- };
-
- #else
- /*
- ** EGS-EI_Window-Struct
- **
- */
-
- struct EI_NewWindow nw = {
- 100,100, /* Starting corner */
- 300,100, /* Width, height */
- 50,50,640,400, /* window not sized */
- NULL, /* screen pointer */
- /* sysGadget for the Window */
-
- EI_WINDOWCLOSE | EI_WINDOWSIZE |
- EI_WINDOWDRAG | EI_WINDOWBACK |
- EI_WINDOWFRONT ,
- NULL, /* Pointer to first gadget */
- "Nervous Lines", /* title */
- /* Flags */
- EI_WINDOWACTIVE |
- EI_SIZEBBOTTOM |
- EI_GIMMEZEROZERO,
- /* EIDCMP-FLAGS */
-
- MIX_CLOSEWINDOW | MIX_NEWSIZE,
-
- NULL, /* MsgPort * */
- { 3 ,1 ,0 ,2 ,1 ,3 ,1 }, /* WinColors */
- NULL, /* MenuPtr */
- NULL /* IntuiGfxPtr */
- };
- /*
- */
-
- #endif
-
- int x[2],y[2],xd[2],yd[2],co,ox[2][16],oy[2][16],xx[128],xlim,ylim;
-
-
- /**
- *
- * main program - Since no command line data is used, and no file I/O
- * is performed, we do not need _main from the library. We eliminate
- * it by calling our main function '_main'.
- *
- **/
- void main()
- {
- register short i;
- register int k;
- register long co;
- register long j;
-
-
- /************************ Set-Up routines **********************************/
- /* Let the auto init code open our libraries for us. */
-
- #ifndef EGS
-
- w = OpenWindow(&nw);
- rp = w->RPort; /* Get the raster port pointer */
- vp = &w->WScreen->ViewPort; /* Get the view port pointer */
- SetAPen(rp,3); /* Set foreground pen to white */
- SetDrMd(rp,JAM1); /* Draw with foreground pen */
-
- xlim = w->Width;
- ylim = w->Height;
-
-
- #else
-
- /*
- ** EGS - Open EGS Libraries and call some
- ** EGS functions
- **
- */
- register long rot=0,blau=0,gruen=0;
-
- EGSGfxBase = OpenLibrary("egsgfx.library",0);
-
- if (EGSGfxBase == NULL )
- crash("Can't open egsgfx.library !");
-
- EGSIntuiBase = OpenLibrary("egsintui.library",0);
-
- if (EGSIntuiBase == NULL )
- crash("Can't open egsintui.library !");
-
-
- w = EI_OpenWindow(&nw);
- rp = w->RPort;
- EG_SetAPen(rp,0);
- EG_SetDrMd(rp,0);
-
- xlim = w->Width;
- ylim = w->Height;
-
- /*
- */
- #endif
-
- for(i=0;i<2;i++)
- {
- x[i] = rand() % xlim + 1;
- y[i] = rand() % ylim + 1;
- xd[i] = rand() % 10 + 1;
- yd[i] = rand() % 10 + 1;
- }
- co = 1;
- j = 0;
- do {
-
- #ifndef EGS
- SetAPen(rp,co);
- Move(rp,x[0],y[0]);
- Draw(rp,x[1],y[1]);
- if((rand() & 127) < 2)
- {
- ++co;
- if(co > 3) co = 1;
- SetAPen(rp,co);
- }
- #else
-
- /*
- ** EGS The equal EGS functions
- **
- **
- */
-
- EG_SetAPen(rp,co);
- EG_Move(rp,x[0],y[0]);
- EG_Draw(rp,x[1],y[1]);
-
-
- if (blau < 64)
- blau++;
- else
- {
- blau=0;
-
- if (gruen < 64)
- gruen++;
- else
- {
- gruen=0;
-
- if (rot < 64)
- rot++;
- else
- {
- rot=0;
- }
-
- }
- }
-
-
- co = ((rot*4)<<24) +
- ((gruen*4)<<16) +
- ((blau*4)<<8);
-
- EG_SetAPen(rp,co);
-
- /*
- */
- #endif
- for(i=0;i<2;i++)
- {
- ox[i][(j+10) & 15] = x[i];
- oy[i][(j+10) & 15] = y[i];
- x[i] += xd[i];
- y[i] += yd[i];
- if(x[i] < 2)
- {
- x[i] = 2;
- xd[i] = -xd[i];
- }
- else if(x[i] > xlim)
- {
- x[i] = xlim;
- xd[i] = -xd[i];
- }
- if(y[i] < 2)
- {
- y[i] = 2;
- yd[i] = -yd[i];
- }
- else if(y[i] > ylim)
- {
- y[i] = ylim;
- yd[i] = -yd[i];
- }
- if(((rand() >> 5) & 127) < 2)
- {
- if(xd[i] < 1) k = 1;
- xd[i] = (rand() >> 5) & 7;
- if(k == 1) xd[i] = -xd[i];
- k = 0;
- }
- if(((rand() >> 5) & 255) < 50)
- {
- if(yd[i] < 1) k = 1;
- yd[i] = (rand() >> 5) & 7;
- if(k == 1) yd[i] = -yd[i];
- k = 0;
- }
- }
- ++j;
-
- if(w->UserPort->mp_SigBit)
- {
- message = (struct EI_EIntuiMsg *)GetMsg(w->UserPort);
- if(message != NULL)
- {
- class = message->Class;
- code = message->Code;
- ReplyMsg((struct Message *)message);
- }
- }
-
- } while(event());
-
- #ifndef EGS
-
- CloseWindow(w);
- #else
- EI_CloseWindow(w);
- crash(NULL);
- /*
- */
- #endif
-
-
- }
-
-
- int event()
- {
- switch(class)
- {
- case MIX_CLOSEWINDOW:
- return(0);
- case MIX_NEWSIZE:
- xlim = w->Width;
- ylim = w->Height;
- return(1);
- }
- return(1);
- }
-
-
- #ifdef EGS
-
- /*
- ** CloseLibs
- */
-
- void crash(char *string)
- {
- if (string != NULL)
- printf("%s\n",string);
-
- if (EGSGfxBase != NULL)
- CloseLibrary(EGSGfxBase);
-
- if (EGSIntuiBase != NULL)
- CloseLibrary(EGSIntuiBase);
-
-
- exit(0);
- }
-
- /*
- */
- #endif
-